cmake_minimum_required(VERSION 3.2)

message(STATUS "Generating build using CMake ${CMAKE_VERSION}")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# store short version to SZARP_VERSION, store long version to version.info (see below)
execute_process(COMMAND "${CMAKE_SOURCE_DIR}/script/version-info" -v "${CMAKE_SOURCE_DIR}/debian/changelog"  OUTPUT_VARIABLE SZARP_VERSION)
add_custom_target( version.info ALL "${CMAKE_SOURCE_DIR}/script/version-info" "${CMAKE_SOURCE_DIR}/debian/changelog" > ${CMAKE_CURRENT_BINARY_DIR}/version.info )

set(PACKAGE_NAME "szarp") # /etc/PACKAGE_NAME/PACKAGE_NAME.cfg
project(${PACKAGE_NAME} LANGUAGES C CXX)

set(szarp_BINARY_STAGE_DIR ${szarp_BINARY_DIR}/stage CACHE INTERNAL "STAGE_DIR")

message(STATUS "Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" _build_type)
message(STATUS "CMAKE_C_FLAGS_${_build_type}: ${CMAKE_C_FLAGS_${_build_type}}")
message(STATUS "CMAKE_CXX_FLAGS_${_build_type}: ${CMAKE_CXX_FLAGS_${_build_type}}")

option(WITH_TESTS "Enable tests" ON)
if (${WITH_TESTS})
	enable_testing()
endif()
option(BUILD_DOC "Enable documentation build" OFF)

include(GNUInstallDirs)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_REQUIRED_LIBRARIES m)
set(CMAKE_REQUIRED_INCLUDES math.h)
set(Python_ADDITIONAL_VERSIONS 2.7)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/libs)

set(PACKAGE_BUGREPORT "devs@newterm.pl")
set(PACKAGE_URL "https://github.com/newterm/szarp")
set(PREFIX "/opt/szarp/")
set(VERSION ${SZARP_VERSION})	# required by some source files
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

include(cmake/install_layout.cmake)
include(cmake/configure.cmake)
include(cmake/compiler.cmake)
include(cmake/packaging.cmake)

add_subdirectory(libSzarp)
add_subdirectory(libSzarp2)
add_subdirectory(python)
add_subdirectory(sender)
add_subdirectory(parcook)
add_subdirectory(cfgdealer)
add_subdirectory(isl)
add_subdirectory(meaner3)
add_subdirectory(iks)
add_subdirectory(extern)
add_subdirectory(wx)
add_subdirectory(utils)
add_subdirectory(unit_tests)
add_subdirectory(resources)
add_subdirectory(script)
add_subdirectory(qt4)

install(FILES version.info DESTINATION "${SZARP_SHAREDIR}" )
install(FILES libs/libpyszbase.so libs/libpysz4.so DESTINATION "${SZARP_LIBDIR}" )
